#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>


char *const env[] = {
  (char *const)"avb = 1231",
  (char *const)"ajfda = 123",
  NULL
};

// 练习进程替换
int main()
{
  printf("father process starts\n");

  if (fork() == 0) // child
  {

    //execl("/usr/bin/ls", "/usr/bin/ls", "-al", NULL); // 注意最后一个参数要传递NULL
    //execl("/usr/bin/bash", "bash", "other.sh", NULL); // 注意最后一个参数要传递NULL 
    //execl("/usr/bin/python3", "python3", "other.py", NULL); // 注意最后一个参数要传递NULL
    
    char *const argv[] = {
      (char *const)"other",
      (char *const)"-a",
      (char *const)"-b",
      NULL
    };

    extern char **environ;
    for (int i = 0; env[i]; ++i)
    {
      putenv(env[i]); 
    }


    execv("./other", argv); 
  }

  waitpid(-1, NULL, 0);
  printf("father process ends\n");


  return 0;
}
